package com.atguigu.jxc.controller;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.*;
import com.atguigu.jxc.service.DamageGoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.ArrayList;
import java.util.Map;

@RestController
public class DamageGoodController {
    @Autowired
    private DamageGoodService damageGoodService;
   // damageListGoodsStr: [{"goodsId":12,
    // "goodsTypeId":10,"goodsCode":"0004",
    // "goodsName":"新疆红枣","goodsModel":"2斤装",
    // "goodsUnit":"袋","lastPurchasingPrice":13,"price":"13","goodsNum":"5","total":65},
    private String goodsTypeName;

    private Integer saleTotal;// 销售总量

   // {"goodsId":33,"goodsTypeId":6,"goodsCode":"0024","goodsName":"卓图女装立领针织格子印花拼接高腰A字裙2017秋冬新款碎花连衣裙","goodsModel":"A字裙","goodsUnit":"件","lastPurchasingPrice":168,"price":"168","goodsNum":"8","total":1344}]
   // ?damageNumber=BS1605766644460
    @PostMapping("/damageListGoods/save")
    public ServiceVO savedamageListGoods(DamageList damageList, String  damageListGoodsStr){
        String replace = damageListGoodsStr.replace("[", "").replace("]","");
        String[] split = replace.split("},");
        ArrayList<DamageListGoods> list = new ArrayList<>();
        for (int i = 0; i < split.length-1; i++) {
            list.add(JSONObject.parseObject(split[i]+"}", DamageListGoods.class));
        }
        list.add(JSONObject.parseObject(split[split.length-1], DamageListGoods.class));
        damageGoodService.save(damageList,list);
        return new ServiceVO(100,"请求成功",null);
    }
    // 报溢单 保存
   @PostMapping("/overflowListGoods/save")
  public  ServiceVO  saveOverflowListGoods(OverflowList overflowList, String overflowListGoodsStr){
       String replace = overflowListGoodsStr.replace("[", "").replace("]","");
       String[] split = replace.split("},");
       ArrayList<OverflowListGoods> list = new ArrayList<>();
       for (int i = 0; i < split.length-1; i++) {
           list.add(JSONObject.parseObject(split[i]+"}", OverflowListGoods.class));
       }
       list.add(JSONObject.parseObject(split[split.length-1], OverflowListGoods.class));
       damageGoodService.saveOverflowListGoods(overflowList,list);
       return new ServiceVO(100,"请求成功",null);
   }
   // 报损 单查询
    @PostMapping("damageListGoods/list")
    public Map<String,Object> getDamageList(String  sTime , String  eTime ){
       return   damageGoodService.getDamageList(sTime,eTime);
    }
    // 报损单 商品 查询
    @PostMapping("damageListGoods/goodsList")
    public  Map<String,Object> getDamageListGoods(Integer damageListId){
        return  damageGoodService.getDamageListGoods(damageListId);
    }
    @PostMapping("overflowListGoods/list")
    public Map<String,Object> getoverflowList(String  sTime , String  eTime ){
        return   damageGoodService.getoverflowList(sTime,eTime);
    }
    // 报损单 商品 查询
    @PostMapping("overflowListGoods/goodsList")
    public  Map<String,Object> getoverflowListGoods(Integer overflowListId){
        return  damageGoodService.getoverflowListGoods(overflowListId);
    }
}

